﻿namespace ExamV5.StudyInfo
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using Wuqi.Webdiyer;

    public class FrmStudyList : Page
    {
        protected Button butQuery;
        protected GridView DataGridInfo;
        protected DropDownList DDLQuery;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected Label labRescordCount;
        protected LinkButton LBFirstPage;
        protected LinkButton LBLastPage;
        protected LinkButton LBNextPage;
        protected LinkButton LBPrevPage;
        private PublicFun publicFun_0 = new PublicFun();
        protected ScriptManager SM;
        protected TextBox txtQuery;
        protected UpdatePanel UPPart;

        protected AspNetPager aspPager;
        protected void butQuery_Click(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = 0;
            this.aspPager.CurrentPageIndex = 1;
            this.method_0();
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void DataGridInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.DataGridInfo.PageIndex = e.NewPageIndex;
            this.method_0();
        }

        protected void DataGridInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //if (e.Row.DataItemIndex != -1)
            //{
            //    e.Row.Attributes.Add("onmouseover", "this.bgColor='#F6F5F5'");
            //    if ((e.Row.DataItemIndex % 2) == 0)
            //    {
            //        e.Row.Attributes.Add("bgcolor", "#FFFFFF");
            //        e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('singleValue')");
            //    }
            //    else
            //    {
            //        e.Row.Attributes.Add("bgcolor", "#FFFFFF");
            //        e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('oldValue')");
            //    }
            //}
            //else
            //{
            //    this.DataGridInfo.Attributes.Add("oldValue", "#FFFFFF");
            //    this.DataGridInfo.Attributes.Add("singleValue", "#FFFFFF");
            //}
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label label = (Label)e.Row.Cells[4].FindControl("labStudyDX");
                e.Row.Cells[3].Text = this.DataGridInfo.DataKeys[e.Row.RowIndex]["PlanStartTime"].ToString() + "<br>" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["PlanEndTime"].ToString();
                double num2 = Convert.ToDouble(this.DataGridInfo.DataKeys[e.Row.RowIndex]["CountTime"].ToString());
                double num3 = Convert.ToDouble(this.DataGridInfo.DataKeys[e.Row.RowIndex]["StudyLongTime"].ToString());
                double num = ((num2 / 60.0) / num3) * 100.0;
                if (num2 >= (num3 * 60.0))
                {
                    label.Enabled = true;
                    label.Text = "<a href='#' onclick=javascript:EditXDInfo('" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["ID"].ToString() + "')><font color=red>" + label.Text + "</font></a>";
                    if (num >= 100)
                        e.Row.Cells[1].Text = "<font color=green>100%</font>";
                    else
                        e.Row.Cells[1].Text = "<font color=green>" + num.ToString("0.00") + "%</font>";
                }
                else
                {
                    label.Enabled = false;
                    e.Row.Cells[1].Text = "<font color=red>" + num.ToString("0.00") + "%</font>";
                }
                e.Row.Cells[2].Text = e.Row.Cells[2].Text + "小时";
                DateTime time2 = Convert.ToDateTime(this.DataGridInfo.DataKeys[e.Row.RowIndex]["PlanStartTime"].ToString());
                DateTime time = Convert.ToDateTime(this.DataGridInfo.DataKeys[e.Row.RowIndex]["PlanEndTime"].ToString());
                if (!((DateTime.Now > time2) ? (DateTime.Now >= time) : true))
                {
                    if (e.Row.Cells[0].Text.Length <= (Convert.ToInt32(this.ViewState["SubStrLen"].ToString()) + 5))
                    {
                        if (!(this.DataGridInfo.DataKeys[e.Row.RowIndex]["StudyType"].ToString() == "A"))
                        {
                            e.Row.Cells[0].Text = "<a href='ShowLStudyDocInfo.aspx?PlanID=" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["ID"].ToString() + "&DocID=" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["StudyDocID"].ToString() + "'  target=_blank>" + e.Row.Cells[0].Text + "</a>";
                        }
                        else
                        {
                            e.Row.Cells[0].Text = "<a href='ShowSStudyDocInfo.aspx?PlanID=" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["ID"].ToString() + "&DocID=" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["StudyDocID"].ToString() + "'  target=_blank>" + e.Row.Cells[0].Text + "</a>";
                        }
                    }
                    else if (!(this.DataGridInfo.DataKeys[e.Row.RowIndex]["StudyType"].ToString() == "A"))
                    {
                        e.Row.Cells[0].Text = "<a href='ShowLStudyDocInfo.aspx?PlanID=" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["ID"].ToString() + "&DocID=" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["StudyDocID"].ToString() + "' title=" + e.Row.Cells[0].Text + "  target=_blank>" + e.Row.Cells[0].Text.Substring(0, Convert.ToInt32(this.ViewState["SubStrLen"].ToString()) + 5) + "…</a>";
                    }
                    else
                    {
                        e.Row.Cells[0].Text = "<a href='ShowSStudyDocInfo.aspx?PlanID=" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["ID"].ToString() + "&DocID=" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["StudyDocID"].ToString() + "' title=" + e.Row.Cells[0].Text + "  target=_blank>" + e.Row.Cells[0].Text.Substring(0, Convert.ToInt32(this.ViewState["SubStrLen"].ToString()) + 5) + "…</a>";
                    }
                }
            }
            if (e.Row.RowType == DataControlRowType.Header)
            {
                if (this.ViewState["SortType"].ToString() != " Desc")
                {
                    switch (this.ViewState["SortFiled"].ToString())
                    {
                        case "PlanName":
                            e.Row.Cells[0].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "CountStudy":
                            e.Row.Cells[1].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "StudyLongTime":
                            e.Row.Cells[2].Controls.Add(new LiteralControl("↓"));
                            return;
                    }
                    e.Row.Cells[0].Controls.Add(new LiteralControl("↓"));
                }
                else
                {
                    switch (this.ViewState["SortFiled"].ToString())
                    {
                        case "PlanName":
                            e.Row.Cells[0].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "CountStudy":
                            e.Row.Cells[1].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "StudyLongTime":
                            e.Row.Cells[2].Controls.Add(new LiteralControl("↑"));
                            return;
                    }
                    e.Row.Cells[0].Controls.Add(new LiteralControl("↑"));
                }
            }
        }

        protected void DataGridInfo_Sorting(object sender, GridViewSortEventArgs e)
        {
            string sortExpression = e.SortExpression;
            if (!(this.ViewState["SortFiled"].ToString() == sortExpression))
            {
                this.ViewState["SortFiled"] = e.SortExpression;
            }
            else if (!(this.ViewState["SortType"].ToString() == " Desc"))
            {
                this.ViewState["SortType"] = " Desc";
            }
            else
            {
                this.ViewState["SortType"] = " ASC";
            }
            this.method_0();
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void DataGridInfo_PreRender(object sender, EventArgs e)
        {
            // 使用<TH>替换<TD> 
            this.DataGridInfo.UseAccessibleHeader = true;
            //HeaderRow将被<thead>包裹，数据行将被<tbody>包裹
            this.DataGridInfo.HeaderRow.TableSection = TableRowSection.TableHeader;
        }

        protected void aspPager_PageChanged(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = this.aspPager.CurrentPageIndex - 1;
            this.method_0();
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void LBFirstPage_Click(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = 0;
            this.method_0();
        }

        protected void LBLastPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageCount > 0)
            {
                this.DataGridInfo.PageIndex = this.DataGridInfo.PageCount - 1;
                this.method_0();
            }
        }

        protected void LBNextPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageIndex < (this.DataGridInfo.PageCount - 1))
            {
                this.DataGridInfo.PageIndex++;
                this.method_0();
            }
        }

        protected void LBPrevPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageIndex > 0)
            {
                this.DataGridInfo.PageIndex--;
                this.method_0();
            }
        }

        private void method_0()
        {
            string selectCommandText = "";
            selectCommandText = "select a.PlanStartTime,a.PlanEndTime,c.CountTime,a.StudyLongTime,c.CountTime/(a.StudyLongTime*60) as CountStudy,a.StudyDocID,a.StudyType,a.ID,a.PlanName,a.StudyLongTime,a.InputTime from StudyPlanInfo a,StudyUser c  where c.UserCode='" + this.httpCookie_0.Value + "' and c.PlanID=a.ID ";
            if (this.txtQuery.Text.Trim() != "")
            {
                selectCommandText = selectCommandText + " and " + this.publicFun_0.CheckString(this.DDLQuery.SelectedItem.Value) + " like '%" + this.publicFun_0.CheckString(this.txtQuery.Text) + "%'";
            }
            selectCommandText = selectCommandText + "  order by " + this.ViewState["SortFiled"].ToString() + " " + this.ViewState["SortType"].ToString();
            SqlConnection selectConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            SqlDataAdapter adapter = new SqlDataAdapter(selectCommandText, selectConnection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet, "DataInfo");
            this.DataGridInfo.DataSource = dataSet.Tables["DataInfo"].DefaultView;
            this.DataGridInfo.DataBind();
            this.labRescordCount.Text = "总共&nbsp;<i>" + dataSet.Tables["DataInfo"].Rows.Count.ToString() + "</i>&nbsp;条记录&nbsp;<b>" + Convert.ToString((int)(this.DataGridInfo.PageIndex + 1)) + "/" + this.DataGridInfo.PageCount.ToString() + "</b>&nbsp;页&nbsp;";
            this.aspPager.RecordCount = dataSet.Tables["DataInfo"].Rows.Count;
            adapter.Dispose();
            selectConnection.Close();
            selectConnection.Dispose();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) && (this.httpCookie_0.Value != ""))
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (Convert.ToInt32(ConfigurationManager.ConnectionStrings["OnlineNum"].ConnectionString) == 0x3a)
                {
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BTHB", "alert('该版本为特惠版，此功能未开放！')", true);
                }
                else if (!base.IsPostBack)
                {
                    if (this.publicFun_0.ReturnPaperData() == "Yes")
                    {
                        if (this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='DayRubric'", "ParmValue").Trim() == "Y")
                        {
                            if (this.publicFun_0.GetValues("select ID from DayRecored where UserCode='" + this.httpCookie_0.Value + "' and Convert(varchar(10),InputTime,120)=Convert(varchar(10),getdate(),120)", "ID") != "")
                            {
                                string str2 = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='ExamWarnShow'", "ParmValue").Trim();
                                if (str2.Trim() == "")
                                {
                                    str2 = "Y";
                                }
                                if ((str2.Trim() == "Y") && (this.Session["IsShow"] == null))
                                {
                                    this.Session["IsShow"] = "Y";
                                    base.ClientScript.RegisterClientScriptBlock(this.Page.ClientScript.GetType(), "LoingScript", "ShowWarningInfo();", true);
                                }
                            }
                            else
                            {
                                base.ClientScript.RegisterClientScriptBlock(this.Page.ClientScript.GetType(), "LoingScript", "ShowDayRubricInfo();", true);
                            }
                        }
                        this.txtQuery.Attributes.Add("onkeydown", "SubmitKeyClick('butQuery');");
                        this.ViewState["SortFiled"] = "ID";
                        this.ViewState["SortType"] = " Desc";
                        string str = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='SubStrLength'", "ParmValue").Trim();
                        if (str.Trim() == "")
                        {
                            str = "20";
                        }
                        this.ViewState["SubStrLen"] = str;
                        this.method_0();
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('此版本暂未授权,请与管理员联系！')", true);
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

